﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;
using $safeprojectname$.Infrastructure.Factories;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace $safeprojectname$.Core.Publishing
{
    [TestClass]
    public class PublishingManagerTest : TestBase
    {
        [TestMethod]
        public void PublishException_Passed()
        {
            PublishingManager.Publish(this, "ExceptionMessage", new Exception("MyException"));

            var appender = LoggingTargets.GetCurrentMemoryAppender();
            var result = appender.GetEvents().First();

            Assert.IsTrue(result.RenderedMessage == "ExceptionMessage");
            Assert.IsTrue(result.ExceptionObject.Message == "MyException");
        }

        [TestMethod]
        public void PublishObject_Passed()
        {
            PublishingManager.Publish(this, Severity.Info, "MyMessage {0} {1}", "to", "you");

            var appender = LoggingTargets.GetCurrentMemoryAppender();
            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "MyMessage to you");
        }

        [TestMethod]
        public void PublishDelegate_Passed()
        {
            PublishingManager.Publish(this, () => "Hello World", Severity.Debug);

            var appender = LoggingTargets.GetCurrentMemoryAppender();
            var result = appender.GetEvents().First();
            Assert.IsTrue(result.RenderedMessage == "Hello World");
        }

        #region Init

        // You can use the following additional attributes as you write your tests:

        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }

        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }

        [TestInitialize]
        public override void MyTestInitialize()
        {
            PublishingManager.Shutdown();
            base.MyTestInitialize(); // Use TestInitialize to run code before running each test
        }

        [TestCleanup]
        public override void MyTestCleanup()
        {
            PublishingManager.Shutdown();
            base.MyTestCleanup(); // Use TestCleanup to run code after each test has run
        }
        #endregion Init
    }
}